package kandl.automation.steprunner.selenium.commands;

import kandl.automation.steprunner.selenium.Command;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.springframework.stereotype.Component;

@Component
class ClickLink implements Command {
    @Override
    public void runCommand(WebDriver driver, String... params) {
        WebElement element = driver.findElement(By.linkText(params[0]));
        if(!element.isDisplayed()) {
            throw new WebElementNotFoundException(params[0] + " is not found.");
        }
        element.click();
    }

    @Override
    public String getName() {
        return "click_link";
    }
}
